package com.likerSai;

/**
 * 盛水最多的容器
 *
 * @author sun.ye
 * @since 2021-05-20 20:56
 */
public class MaxArea {

    public static void main(String[] args) {
        int[] height = new int[]{1,8,6,2,5,4,8,3,7};
        int maxArea = maxArea(height);
        System.out.println(maxArea);
    }

    public  static int maxArea(int[] height){
        int lIndex = 0,
            rIndex = height.length - 1;
        int maxArea = 0;
        while ( lIndex < rIndex ){
            int area = (rIndex - lIndex) * Math.min(height[lIndex],height[rIndex]);
            maxArea = Math.max(maxArea,area);
            if (height[lIndex] < height[rIndex]){
                lIndex++;
            }else {
                rIndex--;
            }
        }

        return maxArea;
    }
}